@namespace SageKing.Studio.Pages.Dashboard.Components
@inherits StudioComponentBase

<div class="pa-4">

    <MudText Typo="Typo.overline">Version history</MudText>
    <MudStack>
        <MudMenu EndIcon="@Icons.Material.Filled.KeyboardArrowDown" Label="Bulk actions" Color="Color.Default" Variant="Variant.Filled" Class="align-self-end" AnchorOrigin="Origin.BottomLeft" Disabled="!HasWorkflowEditPermission">
            <MudMenuItem OnClick="OnBulkDeleteClicked">Delete</MudMenuItem>
        </MudMenu>
        <VerticalWell ExtraPadding="160">
            <MudTable
                @ref="Table"
                ServerData="LoadVersionsAsync"
                T="WorkflowDefinitionSummary"
                OnRowClick="@OnRowClick"
                @bind-SelectedItems="SelectedDefinitions"
                RowStyle="cursor: pointer;"
                MultiSelection="true"
                SelectOnRowClick="false"
                Hover="true"
                Dense="true"
                Bordered="false"
                Striped="false"
                Elevation="0"
                Outlined="true"
                FixedHeader="true">
                <HeaderContent>
                    <MudTh>Published</MudTh>
                    <MudTh>Version</MudTh>
                    <MudTh>Created</MudTh>
                    <MudTh></MudTh>
                </HeaderContent>
                <RowTemplate>
                    <MudTd>
                        @if (context.IsPublished)
                        {
                            <MudIcon Icon="@Icons.Material.Filled.Check" Color="Color.Success"/>
                        }
                    </MudTd>
                    <MudTd>@context.Version</MudTd>
                    <MudTd>@context.CreatedAt.ToString("g")</MudTd>
                    <MudTd style="text-align: right;">
                        <MudMenu Icon="@Icons.Material.Filled.MoreVert">
                            <MudMenuItem Icon="@Icons.Material.Outlined.ZoomIn" OnClick="@(() => OnViewClicked(context))">View</MudMenuItem>
                            <MudMenuItem Icon="@Icons.Material.Outlined.Undo" OnClick="@(() => OnRollbackClicked(context))" Disabled="@(!CanRollback(context))">Rollback to this version</MudMenuItem>
                            <MudMenuItem Icon="@Icons.Material.Outlined.Delete" OnClick="@(() => OnDeleteClicked(context))" Disabled="@(!CanDelete(context))">Delete</MudMenuItem>
                        </MudMenu>
                    </MudTd>
                </RowTemplate>
                <PagerContent>
                    <MudTablePager/>
                </PagerContent>
            </MudTable>
        </VerticalWell>
    </MudStack>

</div>